package com.jhs.kjs.model.file;

import java.io.File;

import javax.servlet.http.HttpServletRequest;

public class FileMangerImage extends AFileManager implements IFileManager {
	private static final String IMAGES = "images";
	private static final String RESOURCES = "resources";
	private String contextUploadPath, contextDownloadPath;

	public FileMangerImage(HttpServletRequest request) {
		this.req = request;
	}
	/**
	 *  resource/image/customerResource 에서 부름
	 */
	protected String getContextDownloadPath() {
		if (contextDownloadPath == null || "".equals(contextDownloadPath)
				|| contextDownloadPath.length() == 0) {
			StringBuilder sb = new StringBuilder();
			contextDownloadPath = sb
					.append(this.req.getSession().getServletContext()
							.getRealPath("/")).append(RESOURCES)
					.append(File.separator).append(IMAGES)
					.append(File.separator).append(FORDER_NAME)
					.append(File.separator).toString();
		}
		return contextDownloadPath;
	}

	/**
	 * ../../customerResource 에 저장
	 */
	protected String getContextUploadPath() {

		if (contextUploadPath == null || "".equals(contextUploadPath)
				|| contextUploadPath.length() == 0) {
			StringBuilder sb = new StringBuilder();
			contextUploadPath = sb
					.append(this.req.getSession().getServletContext()
							.getRealPath("/"))
					.append(File.separator).append(FORDER_NAME)
					.append(File.separator).toString();
		}
		return contextUploadPath;
	}
	@Override
	public String getDownloadFilePath() {
		StringBuilder sb = new StringBuilder();
		contextDownloadPath = sb.append(this.req.getSession().getServletContext().getRealPath("/"))
								.append(File.separator).append(FORDER_NAME)
								.append(File.separator).toString();
		return contextDownloadPath;
	}

}
